package com.gzmu.storage.mapper;

import com.gzmu.storage.entity.Chest;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xiaobo Yan
 * @since 2020-04-16
 */
@Mapper
public interface ChestMapper extends BaseMapper<Chest> {
    @Insert("INSERT INTO t_chest(cabinetid,name,serial,status,intakemax,intakecur,createtime,updatetime,remark) VALUES(#{cabinetid}," +
            "#{name},#{serial},#{status},#{intakemax},#{intakecur},now(),now(),#{remark}) ON DUPLICATE KEY UPDATE cabinetid=#{cabinetid}," +
            "name=#{name},serial=#{serial},status=#{status},intakemax=#{intakemax},intakecur=#{intakecur},updatetime=now(),remark=#{remark}")
    @Options(useGeneratedKeys = true)
    boolean insertAndUpdate(Chest chest);

    @Update( "update t_chest set intakecur = intakecur + 1 where id = #{id};" )
    boolean updateChestAddByID(@Param("id") String id);

    @Update( "update t_chest set intakecur = intakecur - 1 where id = #{id};" )
    boolean updateChestSubByID(@Param("id") String id);

    @Update( "UPDATE t_chest SET status=#{status} WHERE id=#{id}" )
    boolean updateChestStatus(@Param( "id" ) Integer id, @Param( "status" ) Integer status);
}
